package com.douban.crawl.db;

import com.douban.crawl.model.SysUser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class UserDao {
    private BaseDao baseDao = new BaseDao();

    public SysUser getUser(String username) {
        Map<String, String> queryMap = new HashMap<>();
        queryMap.put("username", username);
        ArrayList<SysUser> list = baseDao.getList(SysUser.class, queryMap);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    public SysUser getUser(String username, String password) {
        Map<String, String> queryMap = new HashMap<>();
        queryMap.put("username", username);
        queryMap.put("password", password);
        ArrayList<SysUser> list = baseDao.getList(SysUser.class, queryMap);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    public void save(SysUser sysUser) {
        baseDao.insert(sysUser);
    }
}
